package com.stars.controller.sysdict;

import com.stars.common.annotation.DictUpdate;
import com.stars.common.annotation.Log;
import com.stars.common.base.BaseMsg;
import com.stars.common.base.ResultMsg;
import com.stars.common.enums.OperationType;
import com.stars.common.tree.TreeJson;
import com.stars.controller.BaseController;
import com.stars.entity.dto.sysdict.SysDictDTO;
import com.stars.services.sysdict.SysDictAccessServices;
import com.stars.services.sysdict.SysDictConfigServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * @Title: 数据字典 mybatis dao
 * @author dj
 * @date 2019-10-15 15:49:21
 * @version V1.0
 *
 */
@Slf4j
@RestController
@RequestMapping("/sysDictCtl")
@Api(tags ="数据字典")
public class SysDictCtl extends BaseController{
   @Autowired
   private SysDictAccessServices  sysDictAccessServicesImpl;
   @Autowired
   private SysDictConfigServices  sysDictConfigServicesImpl;

    /**
    * 保存
    * @param treeJson
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "数据字典"+ BaseMsg.MODULAR_ADD,notes = "数据字典"+BaseMsg.MODULAR_ADD)
    @Log(detail = "数据字典"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    @DictUpdate(dict = true)
    public ResultMsg addSysDict(TreeJson treeJson,HttpServletRequest request) throws Exception{
        setAddBaseOrg(treeJson,request,null);
        return sysDictConfigServicesImpl.saveTree(treeJson);
    }
    /**
    * 获取全部的树形数据
    *
    * @return
    * @throws Exception
    */
    @PostMapping("/findTree")
    @ApiOperation(value = "获取全部的资源数据",notes = "获取全部的资源数据")
    @Log(detail = "数据字典"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
    public ResultMsg findTree(SysDictDTO sysDictDTO,HttpServletRequest request) throws Exception {
        setSystemApp(sysDictDTO,request);
        List<SysDictDTO> treeList = sysDictAccessServicesImpl.findTreeList(sysDictDTO);
        return ResultMsg.success(treeList);
    }

}